package com.malty.mall.domain.dto.req.pms;

import com.malty.mall.domain.entity.pms.PmsProductCategory;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.List;

/**
 * @author malty
 */
@Data
@NoArgsConstructor
@ApiModel("商品分类信息")
public class PmsProductCateParam {
    @ApiModelProperty("主键")
    private Long id;
    @ApiModelProperty("父分类")
    private Long parentId;
    @ApiModelProperty("分类名称")
    private String name;
    @ApiModelProperty("分类级别")
    private Integer level;
    @ApiModelProperty("展示状态")
    @Min(value = 0, message = "最小值为0")
    @Max(value = 1, message = "最大值为1")
    private Integer showStatus;
    @ApiModelProperty("导航栏展示状态")
    @Min(value = 0, message = "最小值为0")
    @Max(value = 1, message = "最大值为1")
    private Integer navStatus;
    @ApiModelProperty("描述")
    private String description;

    public PmsProductCateParam(PmsProductCategory category) {
        if (category != null) {
            BeanUtils.copyProperties(category, this);
        }
    }

    public static List<PmsProductCateParam> productCategoryParams(List<PmsProductCategory> list) {
        List<PmsProductCateParam> productCateParams = new ArrayList<>();
        for (PmsProductCategory category : list) {
            productCateParams.add(new PmsProductCateParam(category));
        }
        return productCateParams;
    }
}
